package cn.jishiyu11.xeqb.utils

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter


/**
 * 自己编写的万能ViewHolder
 * by jsy_zj
 */
abstract class CommonAdapter<T>(protected var context: Context, protected var mDatas: List<T>, protected var item_id: Int) : BaseAdapter() {
    protected var layout: LayoutInflater

    init {
        layout = LayoutInflater.from(context)
    }

    override fun getCount(): Int {
        return mDatas.size
    }

    override fun getItem(position: Int): T {
        return mDatas.get(position)
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val holder = ViewHolder[context, parent!!, position, item_id, convertView]
        convert(holder, getItem(position))
        convertlistener(holder, getItem(position))
        return holder.convertView
    }

    protected abstract fun convertlistener(holder: ViewHolder, t: T)

    /**
     * convert
     * @param t t集合的泛型
     *
     */
    abstract fun convert(holder: ViewHolder, t: T)

    override fun notifyDataSetChanged() {
        super.notifyDataSetChanged()
    }
}
	